#include<iostream>
using namespace std;

class complex{
    public:
    complex(int real,int image)
    :_real(real)
    ,_image(image)
    {}
    void print () const
    {
        cout << _real <<"+" << _image <<"i" << endl;
    }

    // friend complex operator +(const complex &rhs,const complex &lhs);
  
    //注意这里要定义为const函数因为下面定义的是const对象，const对象只能调用const类型的函数
    int getreal() const
    {
        return _real;
    }
    int getimage()const{
        return _image;
    }
    private:
    int _real;
    int _image;
};
//我们不对类中私有数据进行调用，我们可以创建公有成员函数，调用公有成员函数返回私有成员
complex operator +(const complex &rhs,const complex &lhs)
{
    return complex(rhs.getreal() + lhs.getreal(),rhs.getimage()+lhs.getimage());
}

void test0()
{
    complex c1(2,3);
    complex c2(3,5);
    //会调用默认的拷贝构造
    complex c3 = c1 + c2;
    c3.print();
}

int main()
{
    test0();
    return 0;
}